home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / dev / e / Bmath.lha / BetterMath / Example.e < prev   
Text File  |  1996-10-16  |  2KB  |  76 lines

  1. -> mini fractal example, also little timing...
  2.  
  3. OPT PREPROCESS,REG=5
  4.  
  5.  
  6. /* Add comment for this line if You want NOFPU version of this example */
  7. #define FPU
  8.  
  9. #ifdef FPU
  10. MODULE 'bettermath/math_881_s','bettermath/math_881_test'
  11. #endif
  12.  
  13. #ifndef FPU
  14. MODULE 'bettermath/math_ieee_s'
  15. #endif
  16.  
  17. MODULE 'dos/dos'
  18.  
  19. CONST TICKS_PER_MINUTE=TICKS_PER_SECOND*60
  20. CONST CALCW=200,HEIGHT=100, DEPTH=25
  21.  
  22. PROC main()
  23.   DEF w,xmax,ymax,x,y,xr,width=3.5,height=2.8,left,top,ds1:datestamp,ds2:datestamp,tct
  24. #ifdef FPU
  25.     IF ftestiffpu()
  26. #endif
  27.  
  28. #ifdef FPU
  29.         WriteF('This is FPU version of this program.\n')
  30. #endif
  31. #ifndef FPU
  32.         WriteF('This is NOFPU version of this program.\n')
  33. #endif
  34.  
  35.         finit()
  36.       IF w:=OpenW(0,11,CALCW+40,HEIGHT+30,$200,$E,'MiniFrac!',NIL,1,NIL)
  37.             DateStamp(ds1)
  38.         top:=fsub(0.0,3.2)
  39.              left:=fsub(0.0,2.0)
  40.             xmax:=ftoreal(CALCW)
  41.             ymax:=ftoreal(HEIGHT-1)
  42.  
  43.         FOR x:=0 TO CALCW-1
  44.             xr:=fadd(fmul(fdiv(ftoreal(x),xmax),width),left)
  45.           FOR y:=0 TO HEIGHT-1 DO Plot(x+20,y+20,calc(xr,fadd(fmul(fdiv(ftoreal(y),ymax),height),top)))
  46.         ENDFOR
  47.             DateStamp(ds2)
  48.             tct:=((ds2.minute-ds1.minute)*TICKS_PER_MINUTE)+ds2.tick-ds1.tick
  49.             WaitIMessage(w)
  50.         CloseW(w)
  51.             WriteF('Ticks:\d\n',tct)
  52.         ELSE
  53.             WriteF('Can''t open window !\n')
  54.         ENDIF
  55.         fend()
  56. #ifdef FPU
  57.     ELSE
  58.         WriteF('Sorry, FPU is needed.\n')
  59.   ENDIF
  60. #endif
  61.  
  62. ENDPROC
  63.  
  64. PROC calc(x,y)
  65.   DEF xtemp,it=0,xc,yc
  66.   xc:=x; yc:=y
  67.  
  68.   WHILE (it++<DEPTH) AND (fcmp(fmul(fadd(fmul(x,x),y),y),16.0)=-1)
  69.         xtemp:=x
  70.  
  71.         x:=fadd(fsub(fmul(x,x),fmul(y,y)),xc)
  72.         y:=fadd(fmul(fadd(xtemp,xtemp),y),yc)
  73.     
  74.   ENDWHILE
  75. ENDPROC it
  76.